<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>3_类中的方法this指向</title>
</head>
<body>
  <script>
    /* class Person {
      constructor(name, age) {
        this.name = name
        this.age = age
      }

      study() {
        // study方法放在了哪里？————类的原型对象上，供实例使用
        // 通过Person实例调用study时，study中的this就是Person实例
        console.log(this)
      }
    }

    const p1 = new Person('Tom', 18)
    p1.study()  //通过实例调用study方法
    const x = p1.study
    const y = p1.study()  // Person {name: 'Tom', age: 18}
    x()
    y()   // y is not a function */

    /* function demo() {
      "use strict"
      console.log(this)   // 严格模式下是 undefined
    }

    demo()

    function demo2() {
      console.log(this)   // Window
    }

    demo2() */
  </script>
</body>
</html>